package org.example.sbringboot1_12.controller;

import jakarta.servlet.http.HttpServletRequest;
import org.example.sbringboot1_12.model.User;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RequestMapping("/param")
@RestController
public class ParamController {
    @RequestMapping("/p1")
    public  String p1(String name){
        return "接收到参数,name:"+name;
    }
    @RequestMapping("/p2")
    public  String p2(Integer age){
        return "接收到参数,age:"+age;
    }
    @RequestMapping("/p3")
    public  String p3(Integer age,String name){
        return "接收到参数,age:"+age+",name:"+name;
    }
    @RequestMapping("/p4")
    public  String p4(HttpServletRequest result){
        String name=result.getParameter("name");
        Integer age= Integer.valueOf(result.getParameter("age"));
        return "接收到参数,age:"+age+",name:"+name;
    }
    @RequestMapping("/p5")
    public String p5(User user){
        return "user:"+user;
    }
    @RequestMapping("/p6")
    public String p6(@RequestParam("userName") String name){
        return "name:"+name;
    }
    @RequestMapping("/p7")
    public String p7(String[] arr){
        return "arr:"+ List.of(arr);
    }
    @RequestMapping("/p8")
    public String p8(@RequestParam List<String> list){
        return "list:"+ list;
    }
    @RequestMapping("/p9")
    public String p9(@RequestBody User user){
        return "user:"+ user;
    }
    @RequestMapping("/article/{articleId}")
    public String p10(@PathVariable("articleId") String articleId){
        return "articleId:"+ articleId;
    }
    @RequestMapping("/article/{articleId}/{name}")
    public String p11(@PathVariable("articleId") String id,@PathVariable("name") String name){
        return "articleId:"+ id+",name: "+ name;
    }
    @RequestMapping("/p12")
    public String p12(@RequestPart("fileName") MultipartFile file){
        System.out.println(file.getOriginalFilename());
        return "文件名称:"+file.getOriginalFilename();
    }
}
